﻿<?php 
	register_nav_menu('main-menu', __('Main Menu'));
	add_theme_support('post-thumbnails'); //Bật tính năng Set Featured Image cho bài viết
	//add_image_size('featured-thumb', 330, 335, true); //Size ảnh thumbnail của .featured-post.

	add_theme_support( 'post-formats', array( 'aside', 'gallery', 'video', 'image', 'audio', 'link', 'quote', 'chat') );
	
    //Insert main.js
	function enqueue_scripts_and_styles() {
    	// Register the script like this for a theme:
    	wp_enqueue_script('dg-main-js', get_template_directory_uri() . '/js/main.js', array(),'20140708');
    	wp_enqueue_script('dg-main-js');

    	// Register the style like this for a theme:
	    wp_register_style( 'dg-main-style', get_template_directory_uri() . '/style.css', array(), '20140708', 'all' );
    	wp_enqueue_style( 'dg-main-style' );
	}
	add_action( 'wp_enqueue_scripts', 'enqueue_scripts_and_styles' );
	
    //Shortcode hien thi tin tuc theo category
    function create_shortcode_homenews($args, $content) {
    	
        $catid = $args['thamsocatid'];
        $catslug = $args['thamsocatslug'];
    	$content = '<section id="'.$catslug.'" class="category skin1">';
    	   $content .= '<header>';
                $content .= '<hgroup>';
    	           $content .= '<h1><a href='.get_category_link($catid).'>'.get_cat_name($catid).'</a></h1>';
            		foreach (get_categories(array('hide_empty' => 0,'title_li' => '','style' => 'list','parent' => $catid,'orderby' => 'id','order' => 'ASC')) as $cat1) :
            		 	$content .= '<h2><a href='.get_category_link($cat1->term_id).'>'.$cat1->name.'</a></h2>';
            		endforeach;
                $content .= '</hgroup>';
                $content .= '<div class="followbox">';
                    $content .= '<ul>';
                        $content .= '<li class="email"><a href="http://feedburner.google.com/fb/a/mailverify?uri=zingnews/xa-hoi" target="_blank">Nhận tin qua Email</a></li>';
                        $content .= '<li class="rss"><a href="http://feeds.feedburner.com/zingnews/xa-hoi" target="_blank">Nhận tin qua RSS</a></li>';
                        $content .= '<li class="zini"><a href="http://zini.vn/news.zing" target="_blank">Theo dõi qua Zini</a></li>';
                    $content .= '</ul>';
                $content .= '</div>';
            $content .= '</header>';

        $query1 = new WP_Query('cat='.$catid.'&posts_per_page=1');
        while ( $query1->have_posts() ) : $query1->the_post(); 
        $type = get_post_format($post->ID);

            $content .= '<article class="featured '.$type.'">';
                $content .= '<p class="type">'.$type.'</p>';
                $content .= '<header>';
                    $content .= '<h1>';
                        $content .='<a href='.the_permalink().'>'.the_title().'</a>';
                    $content .= '</h1>';
                    $content .= '<time datetime='.the_time("jS F Y").'>'.the_time("jS F Y").'</time>';
                $content .= '</header>';
                
                $image = get_the_post_thumbnail($post->ID, 'thumbnail'); 
                if (has_post_thumbnail()) :
                
                $content .= '<div class="cover">';
                    $content .='<a href='.the_permalink().'>'.$image.'</a>';
                $content .= '</div>';
                endif;
                $content .= '<p class="summary">'.get_the_excerpt().'</p>';
                $content .= '<ul class="relate">';
                    $content .= '<li class="">';
                        $content .= '<a href="/Tang-tru-ma-tuy-lao-thang-xe-vao-canh-sat-co-dong-post336825.html#relate-article">Tàng trữ ma túy, lao thẳng xe vào cảnh sát cơ động</a>';
                    $content .= '</li>';

                $content .= '</ul>';
            $content .= '</article>';

        endwhile;

            $content .= '<div class="top">';
               
                $query = new WP_Query( 'cat='.$catid.'&posts_per_page=4&offset=1' );
                while ( $query->have_posts() ) : $query->the_post();
                $type = get_post_format($post->ID);
                $image = get_the_post_thumbnail($post->ID, 'thumbnail'); 
                $content .= '<article class="'.$type.'">';
                    $content .= '<p class="type">'.$type.'</p>';
                    if (has_post_thumbnail()) :
                        $content .= '<div class="cover">';
                            $content .= '<a href='.the_permalink().' title='.the_title_attribute().'>'.$image.'</a>';
                        $content .= '</div>';
                    endif;
                   $content .= '<header>';
                        $content .= '<h1>';
                            $content .= '<a href='.the_permalink().'>'.the_title().'</a>';

                        $content .= '</h1>';
                        $content .= '<time datetime='.the_time("jS F Y").'>'.the_time("jS F Y").'</time>';
                    $content .= '</header>';
                $content .= '</article>';
                endwhile;    
            $content .= '</div>';
            $content .= '<article class="aside ">';
                $content .= '<p class="type"></p>';
                $content .= '<div class="cover" style="background-image: url(http://img.v3.news.zdn.vn/w120/Uploaded/xpcwvovb/2014_07_03/via_thumb.jpg)">';
                    $content .= '<a href="/Kho-so-vi-cau-nho-dung-manh-ngoai-y-muon-post432751.html#home_cate|tinphu"></a>';
                $content .= '</div>';
                $content .= '<header>';
                    $content .= '<h1>';
                        $content .= '<a href="/Kho-so-vi-cau-nho-dung-manh-ngoai-y-muon-post432751.html#home_cate|tinphu">Khổ sở vì "cậu nhỏ" dũng mãnh ngoài ý muốn</a>';
                    $content .= '</h1>';
                    $content .= '<time datetime="2014-07-03 09:56+0700"> 09:56 ngày 03/07/2014</time>';
                $content .= '</header>';
            $content .= '</article>';
		$content .= '</section>';
		
        return $content;
	}
	add_shortcode('Shortcode_DG_Homenews', 'create_shortcode_homenews');